/** \file    bmpmorph.h
  * \brief   Bitmap morthological operations.
  * \date    2001 - 2005
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/include/imglib/bmpmorph.h,v 1.3 2005/04/29 18:24:12 cscom1r4 Exp $
  */

#ifndef _bmpmorph_h_
#define _bmpmorph_h_

#include "bitmap.h"

namespace img {

///the output pixel is set to zero if the corresponding input pixel or any of its 4(8) neighboring pixels are 0.
void erode4( bitmap &bmp, const bitmap &src );
void erode8( bitmap &bmp, const bitmap &src );

///performs erosion several times
void erode4( bitmap &bmp, const bitmap &src, int iterations );
void erode8( bitmap &bmp, const bitmap &src, int iterations );

///the output pixel is set to 1 if the corresponding input pixel or any of its 4(8) neighboring pixels are 1.
void dilate4( bitmap &bmp, const bitmap &src );
void dilate8( bitmap &bmp, const bitmap &src );

///performs dilation several times
void dilate4( bitmap &bmp, const bitmap &src, int iterations );
void dilate8( bitmap &bmp, const bitmap &src, int iterations );

///performs iterations of erosion followed by iterations of dilation
///source and destination bitmaps may coincide (temporary storage will be created and used in either case)
void open4( bitmap &bmp, const bitmap &src, int iterations );
void open8( bitmap &bmp, const bitmap &src, int iterations );

///performs iterations of dilation followed by iterations of erosion
///source and destination bitmaps may coincide (temporary storage will be created and used in either case)
void close4( bitmap &bmp, const bitmap &src, int iterations );
void close8( bitmap &bmp, const bitmap &src, int iterations );

// inplace functions

inline void erode4(bitmap & bmp) {
	bitmap tmp(bmp);
	erode4(bmp, tmp);
}

inline void erode8(bitmap & bmp) {
	bitmap tmp(bmp);
	erode8(bmp, tmp);
}

inline void erode4(bitmap & bmp, int iterations) {
	bitmap tmp(bmp);
	erode4(bmp, tmp, iterations);
}

inline void erode8(bitmap & bmp, int iterations) {
	bitmap tmp(bmp);
	erode8(bmp, tmp, iterations);
}

inline void dilate4(bitmap & bmp) {
	bitmap tmp(bmp);
	dilate4(bmp, tmp);
}

inline void dilate8(bitmap & bmp) {
	bitmap tmp(bmp);
	dilate8(bmp, tmp);
}

inline void dilate4(bitmap & bmp, int iterations) {
	bitmap tmp(bmp);
	dilate4(bmp, tmp, iterations);
}

inline void dilate8(bitmap & bmp, int iterations) {
	bitmap tmp(bmp);
	dilate8(bmp, tmp, iterations);
}

inline void open4(bitmap & bmp, int iterations)
	{ open4(bmp, bmp, iterations); }

inline void open8(bitmap & bmp, int iterations)
	{ open8(bmp, bmp, iterations); }

inline void close4(bitmap & bmp, int iterations)
	{ close4(bmp, bmp, iterations); }
	
inline void close8(bitmap & bmp, int iterations)
	{ close8(bmp, bmp, iterations); }

} // img

#endif //_bmpmorph_h_
